from django.shortcuts import render
from django.db import transaction
from rest_framework.views import APIView
from rest_framework.response import Response
import re
# Create your views here.
class OrderView(APIView):
    pass


from alipay import AliPay
from shop_project import settings
import os
with open(os.path.join(settings.BASE_DIR, 'order/keys/pub_key.txt')) as f:
    pub_key = f.read()  # 读取公钥
with open(os.path.join(settings.BASE_DIR, 'order/keys/pri_key.txt')) as f:
    pri_key = f.read()  # 读取私钥
my_alipay=AliPay(
    appid='2021000121613751',
    app_notify_url=None,
    app_private_key_string=pri_key,
    alipay_public_key_string=pub_key,
    sign_type='RSA2',
    debug=True
)
def get_url(order_id,total_amount):
    params=my_alipay.api_alipay_trade_page_pay(
        subject='大米商城',
        out_trade_no=None,
        total_amount=total_amount,
        return_url=None,
        notify_url=None

    )
    url = 'https://openapi.alipaydev.com/gateway.do?' + params
    return url

class OrderVie(APIView):
    def get(self,request):
        if request.user_info:
            uid=request.user_info.get('uid')
            user=User.objects.get(id=uid)
        else:
            return Response({'code':400,'msg':'用户未登入'})
        orders_data=user.orde_set.all()
        orders_list=[]
        for i in orders_data:
            orders_list.append({

            })

